﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Navigation;
using SilverlightOracle.WCFService;
namespace SilverlightOracle
{
    public partial class MainQuanTri : Page
    {
        ServiceClient webservice = new ServiceClient();
        public MainQuanTri()
        {
            InitializeComponent();
            webservice.GetSessionValueCompleted += new EventHandler<GetSessionValueCompletedEventArgs>(webservice_GetSessionValueCompleted);
            webservice.GetSessionValueAsync();
           // stk.Children.Add(new MainPage());
            stk2.Children.Add(new QuanTriThiSinh());
            stk3.Children.Add(new QuanTriTruong());
            stk4.Children.Add(new QuanTriNguoiDungTest());
            stk6.Children.Add(new QuantriCapNhat());
        }

        void webservice_GetSessionValueCompleted(object sender, GetSessionValueCompletedEventArgs e)
        {
            if (e.Result != "")
            {
                webservice.GetQuyenTruyCapCompleted += new EventHandler<GetQuyenTruyCapCompletedEventArgs>(webservice_GetQuyenTruyCapCompleted);
                webservice.GetQuyenTruyCapAsync(Convert.ToInt32(e.Result));
            }
            else
            {
                MessageBox.Show("Yêu cầu đăng nhập lại để tiếp tục ");
                App.NavigateToPage(new MainPage());
            }
        }

        void webservice_GetQuyenTruyCapCompleted(object sender, GetQuyenTruyCapCompletedEventArgs e)
        {
            if (e.Result != 0)
            {
                if (e.Result == 1)
                {
                    button1.Visibility = Visibility.Collapsed;
                    button2.Visibility = Visibility.Collapsed;
                    button3.Visibility = Visibility.Collapsed;
                    button5.Visibility = Visibility.Collapsed;
                }
            }
            else
            {
                MessageBox.Show("Yêu cầu đăng nhập lại để tiếp tục ");
                App.NavigateToPage(new MainPage());
            }
        }

        // Executes when the user navigates to this page.
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
        }

        private void LayoutRoot_Loaded(object sender, RoutedEventArgs e)
        {
            Onload.Begin();
            Onload.Completed += new EventHandler(Onload_Completed);
        }

        void Onload_Completed(object sender, EventArgs e)
        {
            //VisualStateManager.GoToState(this, "View1", true);
        }

        private void button4_Click(object sender, RoutedEventArgs e)
        {
            var cw = new InsertThiSinh();
            cw.Show();
        }

        private void button_Click(object sender, RoutedEventArgs e)
        {
            App.NavigateToPage(new MainPage());
        }

        private void button6_Click(object sender, RoutedEventArgs e)
        {
            webservice.SetSessionValueCompleted += new EventHandler<System.ComponentModel.AsyncCompletedEventArgs>(webservice_SetSessionValueCompleted);
            webservice.SetSessionValueAsync("");
            //webservice.SetSessionValueCompleted += new EventHandler<System.ComponentModel.AsyncCompletedEventArgs>(webservice_SetSessionValueCompleted);
            //webservice.SetSessionValueAsync("");
        }

        void webservice_SetSessionValueCompleted(object sender, System.ComponentModel.AsyncCompletedEventArgs e)
        {
            MessageBox.Show("Thoát khỏi hệ thống quản trị !");
            App.NavigateToPage(new MainPage());
        }

    }
}
